import pandas as pd
import datetime
import pytz
import numpy as np

integer_fmt = lambda x: '' if pd.isnull(x) else "{:d}".format(int(x))

float_fmt = lambda x: '' if (pd.isnull(x) or x in (np.inf, -np.inf)) else "{:,.2f}".format(x)

percentage_fmt = lambda x: '' if (pd.isnull(x) or x in (np.inf, -np.inf)) else '{:.1%}'.format(x)

format_ts = lambda x: datetime.datetime.utcfromtimestamp(int(x))\
  .replace(tzinfo=pytz.UTC).strftime("%Y-%m-%d %H:%M:%S %Z")

def formatNumber(num):
  formatted = None
  if num is not None:
    formatted = '{:,.3f}'.format(float(num))
  return formatted

def formatPrice(price):
  price = str('%.10f' % float(price))
  price_str = ''
  drop = True
  for i in price[::-1]:
    if i != '0':
      drop = False
    if not drop:
      price_str += i
  price_str = price_str[::-1]
  if price_str.endswith('.'):
    price_str = price_str[:-2]
  return price_str

